home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 8
/
The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO
/
dosutils
/
fortn611.zip
/
FORTUNE.DOC
< prev
next >
Wrap
Text File
|
1996-11-30
|
23KB
|
503 lines
FORTUNE.DOC 1 Revised: 11-30-96
The FORTUNE.EXE program adds some tuning features to the DOS FOR command (FOR
tune, fortune, what the heck). These features can in some way be applied to
commands accepting regular DOS wildcards. Features include:
* Results of command are written to a batch file which you can review before
you run it. Lets you subsequently edit it if desired and lets you see
exactly what commands will happen when you run it.
* You can also try the commands interactively if they don't require that
much memory to run.
* Ability to embed redirection indicators in a command (see next example).
* Ability to separate the file name and file extension. For example:
FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
* Ability to identify individual characters in the the file name and extension.
For example:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
* Ability to specify a character other than "%" for the delimiter so you can
avoid worrying about different syntax in batch command vs command line.
* Ability to have batch file pause after each command so results can be
reviewed.
* Ability to specify incrementation in the file names. For example:
FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
* Ability to specify multiple statements on one command line.
* Ability to process children subdirectories (/S option) at same time. For
example:
FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
FORTUNE *.BAT /S DEL %A
* Ability to exclude up to 10 file specifications from consideration.
* Ability to do those tough PKZIP commands that you always wanted to do. Like
compress all *.FLI files in your subdirectory to a ZIP of the same name as
the original file:
FORTUNE *.FLI /DO PKZIP -M %R %e
Or move all WAV files into ZIP files with the same name as the WAV file
(separate ZIP for each WAV file):
FORTUNE *.WAV PKZIP -M %R %R.%E
* In addition, you can use the command to create a file which contains a
series of commands including a header and footer section which can be used
for some batch functions.
The DOS FOR command:
Quite a few DOS users are unaware of the DOS FOR command. It allows you to do a
single command over a series of files and provides an easy way to use wildcards
with commands that don't accept them. For example, if you want to type a number
of files to your screen, you can say something like:
FOR %A IN (*.TXT) DO TYPE %A
DOS looks at your IN specification and figures out what file names are covered
by that request. The request can include path information if desired and can
have multiple specification (e.g. "...IN (*.TXT \BAT\*.DOC)...").
FOR then substitutes the file name itself in for whatever variable you specify
in the first parameter after "FOR" ("%A" here). This variable is a single
character (A to Z) preceded by a single percent sign (%). (If FOR is used in a
batch command, you have to use two percent signs (%%) instead.)
FORTUNE.DOC 2 Revised: 11-30-96
FOR then looks at the command following the keyword "DO" and executes that
command. If it finds the variable name in the command, it substitutes the name
of the file for that variable.
So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT, and
CHARLIE.TXT--and you ran the command, it would actually do three commands for
you:
TYPE ABLE.TXT
TYPE BAKER.TXT
TYPE CHARLIE.TXT
All in all, FOR is a *very* useful command. There are also some DOS tricks that
you can use to make the command even more useful but, frankly, I always forget
the tricks. (If someone would like to e-mail them to me, I'll throw them in
here.) In any case, even past the tricks, the FORTUNE command provides even more
features.
FORTUNE wildcards and special characters:
The FORTUNE.EXE program extends the functionality of the DOS FOR command by
providing ways of splitting up the parts of the file name and manipulating the
parts. For example, someone in my office had a mess of files that had to be
renamed as an open parenthesis, followed by the first six characters of the file
name, followed by a close parenthesis. Not too terrible to handle with my text
editor but it hadn't occurred to her. Using FORTUNE, however, it's pretty easy:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
And then you run the newly-created batch file (DOIT.BAT).
Similarly, someone wanted me to rename a mess of files so they had sequential
names. I had to write a program to handle it. Definitely beyond his
capabilities. Again, using FORTUNE it's pretty easy:
FORTUNE IN *.TXT DO RENAME %A %1*.%0001
And again you run the DOIT.BAT file.
Within the command (DO command), FORTUNE allows you to include a number of
indicators. The character which indicates that it's a special character is
typically "%" but you can change this with the /VAR=char option in FORTUNE. All
of the examples here use the default /VAR=% setting.
NOTE TO 4DOS USERS: 4DOS automatically translates %x characters even if used on
the command line. As such, 4DOS users *have* to use a different /VAR=x setting
to use FORTUNE. FORTUNE detects that you are running 4DOS and typically changes
the default /VAR=% to /VAR=@.
FORTUNE.DOC 3 Revised: 11-30-96
In many cases, the indicators are case sensitive; there's a difference between
%p and %P (presuming the default /VAR=% delimiter). Typically, the lowercase
variants are cumulative. %P gives you just the path whereas %p throws in the
drive information too.
%a translates into the entire file name (begins with drive,
colon, \, path, \, file root, ., file extension).
Use %R.%E if you want the filename without the drive/path info
%D translates into the drive (not followed by :)
%d translates into the drive (followed by :)
%P translates into path (not preceded or followed by \)
%p translates into path (begins with drive, colon, \, path, \)
%R translates into file name root
%r translates into file name root (begins with drive, colon, \,
path, \)
%E translates into file name extension
%e translates into file name extension (begins with drive, colon,
\, path, \, file name root, .)--same as %a
%1 to %8 characters 1 to 8 in the file name root
%X to %Z characters 1 to 3 in file name extension (case insignificant;
%X is the same as %x)
%* replaces the character with the standard "*" wildcard
%? replaces the character with the standard "?" wildcard
Unless preceded by the /VAR=x delimiter, the standard DOS wildcards--"*" and
"?"--are supported within the file name. "...DO RENAME %A Q*.Y*" will actually
generate commands with the letters filled in (if the file name is APPLES.ARE,
the command will be RENAME QPPLES.YRE).
If you want to actually write out the commands and leave in the "*" or "?"
characters, precede the characters with "%" or whatever. For example, "FORTUNE
(*.001) DO COPY %R.0%* %R.TOP" will generate something like "COPY TN960402.0*
TN960402.TOP" whereas "FORTUNE (*.001) DO COPY %R.0* %R.TOP" will generate "COPY
TN960402.001 TN960402.TOP".
All other characters in the command string are passed as given.
FORTUNE.DOC 4 Revised: 11-30-96
Using the above characters, if you have two files C:\AUTOEXEC.BAT and
D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%A C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%D C D
%d C: D:
%P (null) WAYNE
%p \ D:\WAYNE\
%R AUTOEXEC MYSTUFF
%r C:\AUTOEXEC D:\WAYNE\MYSTUFF
%E BAT TXT
%e C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%1 A M
%2 U Y
%3 T S
%4 O T
%5 E U
%6 X F
%7 E F
%8 C (null)
%X B T
%Y A X
%Z T T
Special translations:
%[ translates into <
%] translates into >
%0nnnn incrementer field (where "nnnn" is any number of digits;
translates into a numeric field which has the same number of
digits; the first number will be the value of "nnnn" and
subsequent files will be incremented by the value specified in
the /+n or /-n parameter (defaults to /+1)
FORTUNE.DOC 5 Revised: 11-30-96
Using a command file for special cases:
In addition, FORTUNE supports some options that might be used outside of a batch
file. (There are also several uses for this within a batch command but I won't
go into them here. Think about it on your own.) For example, let's say you have
an FTP program and you want to log onto the site and upload all of the *.TXT
files in your subdirectory. Normally, you'd do this by typing something like
this in response to the expected prompts:
ftp
ftp.cu.nih.gov (the name of the ftp site you're logging onto)
anonymous (your userid--I know, anonymous logins aren't
trusted for uploads; use your own userid)
bguthrie@nmaa.org (your password)
cd pub
cd incoming
Now, for each of the files you have, you'd have to enter a command like "send
filename", typically followed by a blank line when prompted for the recipient
file name.
Finally, after you're all done, you'd typically issue a "quit" command.
Thinking about it, you can use redirection in DOS to say "FTP < filename", as
long as the lines in the text file "filename" contain all of the statements in
sequence that you need to issue.
FORTUNE lets you specify a command file which contains a "header" section
(commands to be sent beforehand), a "main" section (commands to be sent for each
filename), and a "footer" section (commands to be send afterward). Each section
is optional and may consist of up to 20 commands. In our example, your command
file (we'll call it "FORTUNE.FTP" in this case) might look like this:
/header
ftp
ftp.cu.nih.gov
anonymous
bguthrie@nmaa.org
cd pub
cd incoming
/main
send %A
(blank line)
/footer
quit
The commands within the "main" section are repeated for each file and can
contain all of the standard FORTUNE features for the command section.
FORTUNE.DOC 6 Revised: 11-30-96
The sections can appear in any order.
To bring in the command file, specify "/DO @filename" instead of "/DO command".
So, your command line might be:
FORTUNE IN (*.TXT) DO @FORTUNE.FTP
This will create a DOIT.BAT file which, in fact, does not contain batch command
statements at all. If this bothers you, specify a different output file name if
you want. Then, to process this file in your FTP command, use standard
redirection:
FTP < DOIT.BAT
Note that using the command file feature disables processing of the FORTUNE
parameters which are specific to batch files. These ignore parameters are:
/ECHO, /-ECHO, /ABEND, /-ABEND, /P, and /-P.
In addition, you can specify a file that contains the filenames to process by
using "/IN @filename". This feature can be very handy when /-CHECK is specified
and the file itself contains file names on a remote host. For example, this is
useful if you're trying to run something like FORTUNE on an ftp host over the
Internet to issue a series of "get" commands on that host.
One disadvantage of the /-CHECK parameter is that it will not parse out the file
name at all so only %A-like requests will do any good.
Specifying parameters:
Parameters for this program can be set in the following ways. The last setting
encountered always wins:
- Read from an *.INI file (see BRUCEINI.DOC file),
- Through the use of an environmental variable (SET FORTUNE=whatever), or
- From the command line (see "Syntax" below)
FORTUNE.DOC 7 Revised: 11-30-96
Syntax:
FORTUNE { IN (set) | IN filespec | /IN (set) | /IN filespec | filespec }
[ /AS filename ] [ /OVERWRITE | /APPEND | /-OVERWRITE | /OVERASK ]
[ /VAR=char ] [ /DELIM=chars ] [ /+n | /-n ] [ /S ] [ /Xfilespec ] ...
[ /-ECHO ] [ /-ABEND ] [ /P ] [ /RUN ] [ /-PROMPT ]
[ /-CHECK ] [ /-WIPE ] [ /MONO ] [ /Iinitfile | /-I ] [ /? ]
{ DO command | /DO command | command }
where:
"IN (set)" lets you specify the file names to be processed. Multiple file
specifications should be separated by a space or a semicolon. The "IN" can be
preceded by a "/" if desired. If only one file specification is provided, you
can skip the parentheses. You can specify "%PATH%" (depending on the value of
the /DELIM=chars option) if you want. A file specification is required for
FORTUNE.
You can specify an input file that contains the file list to process. This is
done using "@filename" instead of "set" or "filespec".
It's possible to leave off the "IN" (or its derivatives) as well as the
parentheses if your file specification(s) include a "/", "*", or "?" character.
For example:
FORTUNE *.BAS *.DOC DO TYPE %A
"/AS filename" tells the command the name of the batch file to create with the
resulting commands. By default, this file will be called DOIT.BAT and it will
be created in your default subdirectory.
"/OVERWRITE" says to write over any output file that's already there.
"/APPEND" says to add the new records at the end of any output file that's
already there. Note that FORTUNE uses several DOS labels every time it executes
and concatenation is typically not recommended.
"/-OVERWRITE" says to abort if the output file exists already.
"/OVERASK" says to prompt if the output file exists already; this is the
default.
"/VAR=char" indicates the character to use as the special character indicator.
This typically defaults to "/VAR=%" under DOS and "/VAR=@" under 4DOS. The
hassle with this is that if you invoke FORTUNE from a batch file, you'll have to
remember to use %% instead of %. If you pick another character (like /VAR=^),
that's not necessary.
FORTUNE.DOC 8 Revised: 11-30-96
"/DELIM=chars" allows you to indicate delimiters to use between statements
within the DO command. Defaults to "/DELIM=$$". This allows you to process
multiple statements in a single FORTUNE command. For example:
FORTUNE IN *.BAS DO COPY %A \TEMP $$ TYPE \TEMP\%R.%E
Note that the number of characters can be any length (including one character).
Your only consideration is that the characters do not appear together in your
command otherwise. The characters are case insignificant ("/DELIM=newline" and
"/DELIM=NEWLine" are the same thing).
"/+n" and "/-n" allow you to specify the increment/decrement value to be used
where %0nnnn indicators are used in the command line. Defaults to "/+1".
"/S" processes the children subdirectories as well. So you could do something
like any of the following:
FORTUNE IN (\*.BAS) /S COPY %A LPT1:
FORTUNE IN (\OLD*.TXT) /S DO DELETE %A
The next example is a little bizarre. Let's say you're using anti-virus
protection program that maintains a read-only file in each subdirectory with all
of the virus signatures for the files in that subdirectory. You decide you no
longer want to use that program again but you have a zillion of these files and
they're all read-only. The following example would search them all out, reset
them to not be read-only, and then delete them.
FORTUNE IN (\VIRCK.SIG) /S DO ATTRIB %A -R $$ DEL %a
"/Xfilespec" says to exclude certain filespecs from being considered. You can
specify up to 10 exclusion parameters but each must have their own /Xfilespec
statement. For example, you could process all *.BAS files except D*.BAS files
by saying "FORTUNE IN (*.BAS) /XD*.BAS DO TYPE %A".
"/ECHO" says to turn ECHO ON in the batch file. This will show the command
being executed before it executes. This is initially the default.
"/-ECHO" says to turn ECHO OFF in the batch file.
"/ABEND" (abnormal end) says to use standard DOS errorlevel trapping to see if
there was an error in running the command. If any non-0 errorlevel condition is
encountered (e.g. an error has occurred), the batch file will branch out,
skipping the rest of the statements in the batch file and aborting. Note that
not all commands return decent errorlevel codes. COPY, for example, doesn't set
an errorlevel to indicate that the file could not be found. "/ABEND" is the
initially the default.
"/-ABEND" says to skip errorlevel testing.
"/P" (or "/PAUSE") says to add a PAUSE statement after each statement that's
executed. If you don't like what you see, you can press Ctrl-Break and get out
of the batch file.
"/-P" (or "/-PAUSE") skips the PAUSE statements. This is typically the default.
FORTUNE.DOC 9 Revised: 11-30-96
"/RUN" says to try to run the commands interactively instead of writing out the
batch file. This only works for commands that don't take much memory (like
RENAME and COPY commands). The default is initially "/-RUN".
"/-RUN" says to write the commands out to the standard batch file. This is the
initially the default.
"/PROMPT" says that if you're running the commands interactively, ask whether to
process this command. This is initially the default if "/RUN" is used.
"/-PROMPT" says to skip the prompts for each command. The default is initially
"/PROMPT".
"/CHECK" says that when an "/IN @filename" is used, verify each data sets'
existence. This is initially the default.
"/-CHECK" skips the data set checking. This is useful when you're issuing
something like a series of GET commands using FTP; the data sets in the "/IN
@filename" may be on a remote host which can't be verified when FORTUNE is run.
Initially defaults to "/CHECK".
"/WIPE" says to kill the batch file (e.g. DOIT.BAT) after successful
completion. This produces an annoying error message ("Batch file missing") but
may be preferable to keeping the batch file around afterward. Initially
defaults to "/WIPE".
"/-WIPE" says to keep the batch file around after completion. This avoids the
ugly error message but leaves the file in your subdirectory. Initially defaults
to "/WIPE".
"/MONO" (or "/-COLOR") does not try to override screen colors. Initially
defaults to "/COLOR".
"/COLOR" (or "/-MONO") allows screen colors to be overridden. This is initially
the default.
"/Iinitfile" says to read an initialization file with the file name "initfile".
The file specification *must* contain a period. Initfiles are described in the
BRUCEINI.DOC file. Initially defaults to "/IFORTUNE.INI".
"/-I" (or "/INULL") says to skip loading the initialization file.
"/?" or "/HELP" or "HELP" shows you the syntax for the command.
FORTUNE.DOC 10 Revised: 11-30-96
"DO command" (or "/DO command" or just "command") specifies the command(s) to be
executed. The slash before "DO" is optional. A command is required. Multiple
commands can be specified if they are separated using the characters specified
in the /DELIM=chars parameter. You can also use a command file by using /DO
@filename; see the previous discussion on "Using a command file for special
cases".
In most cases, the use of the "DO" (or "/DO") parameter is actually unnecessary.
The routine typically treats all of the following as identical:
FORTUNE IN (*.BAS *.DOC) /DO TYPE %A
FORTUNE IN (*.BAS *.DOC) TYPE %A
FORTUNE *.BAS *.DOC TYPE %A
However, using the "DO" (or "/DO") parameter adds an extra left of error
checking and its use it encouraged.
Return codes:
FORTUNE returns the following ERRORLEVEL codes:
0 = no problems, files found and batch file created
1 = no problems, no files met specifications
250 = operation aborted by pressing Escape
255 = syntax problems, file not found, or /? requested
Author:
This program was written by Bruce Guthrie of Wayne Software. It is free for use
and redistribution provided relevant documentation is kept with the program, no
changes are made to the program or documentation, and it is not bundled with
commercial programs or charged for separately. People who need to bundle it in
for-sale packages must pay a $50 registration fee to "Wayne Software" at the
following address.
Additional information about this and other Wayne Software programs can be found
in the file BRUCE.DOC which should be included in the original ZIP file. The
recent change history for this and the other programs is provided in the
HISTORY.ymm file which should be in the same ZIP file where "y" is replaced by
the last digit of the year and "mm" is the two digit month of the release;
HISTORY.611 came out in November 1996. This same naming convention is used in
naming the ZIP file (FORTNymm.ZIP) that this program was included in.
Comments and suggestions can also be sent to:
Bruce Guthrie
Wayne Software
113 Sheffield St.
Silver Spring, MD 20910
fax: (301) 588-8986
e-mail: bguthrie@nmaa.org
http://hjs.geol.uib.no/guthrie/
Please provide an Internet e-mail address on all correspondence.